<template>
	<view class="mine-container" :style="{height: `${windowHeight}px`}">
		<view class="box-bg">
			<uni-nav-bar dark shadow leftText="个人中心" right-icon="redo" />
		</view>
		<!--顶部个人信息栏-->
		<view class="header-section">
			<view class="flex padding justify-between">
				<view class="flex align-center">
					<view v-if="!avatar" class="cu-avatar xl round bg-white">
						<view class="iconfont icon-people text-gray icon"></view>
					</view>
					<image v-if="avatar" @click="handleToAvatar" :src="avatar" class="cu-avatar xl round"
						mode="widthFix">
					</image>
					<view v-if="!name" @click="handleToLogin" class="login-tip">
						点击登录
					</view>
					<view v-if="name" class="user-info">
						<view class="u_title" @click="handleToInfo">
							{{ name }}
						</view>
						<view @click="handleToAddress" style="display: flex;">
							<view>
								<uni-icons type="location" size="20"></uni-icons>
							</view>
							<view class="u_address">
								收货地址
							</view>
						</view>
					</view>

				</view>
				<view @click="handleToEditInfo" class="flex align-center " style="background-color: ;">
					<text style="color:black;">编辑资料</text>
					<view class="iconfont icon-right"></view>
				</view>
			</view>
		</view>

		<view class="content-section">
			<view class="flex justify-between bg-cyan" style="background-color:rgb(241,241,241); padding: 10px;">
				<view>
					<text class=" text-bold" style="color:black">我的服务</text>
				</view>
			</view>
			<view class="mine-actions grid col-3 text-center">
				<view class="action-item" @click="handleMyService('MyOrder')">
					<view class="iconfont icon-wodedingdan text-yellow icon"></view>
					<text class="text">我的订单</text>
				</view>
				<view class="action-item" @click="handleMyService('WaitPayment')">
					<view class="iconfont icon-daifukuan text-green icon"></view>
					<text class="text">待付款</text>
				</view>
				<view class="action-item" @click="handleMyService('WaitShipped')">
					<view class="iconfont icon-daifahuo text-blue icon"></view>
					<text class="text">待发货</text>
				</view>
				<view class="action-item" @click="handleMyService('WaitReceive')">
					<view class="iconfont icon-daishouhuo text-red icon"></view>
					<text class="text">待收货</text>
				</view>
				<view class="action-item" @click="handleMyService('WaitComment')">
					<view class="iconfont icon-daipingjia text-purple icon"></view>
					<text class="text">待评价</text>
				</view>
				<view class="action-item" @click="handleMyPet()">
					<view class="iconfont icon-wodeshoucang text-orange icon"></view>
					<text class="text">我的服务</text>
				</view>

			</view>


			<view class="">
				<view class="flex justify-between">
					<view>
						<text class=" text-bold" style="padding: 10px;">猜你喜欢</text>
					</view>
				</view>
				<view class="mine-actions grid col-2 text-center">
					<view class="actions-favorites">
						<swiper :indicator-dots="false" :autoplay="true" :interval="3000" :duration="1000">
							<swiper-item v-for="(item,index) in carouselList" :key="index">
								<image :src="item.imgUrl" class="carousel-image" mode=""></image>
							</swiper-item>
							<swiper-item>
								<view class="swiper-item"></view>
							</swiper-item>
						</swiper>
					</view>
					<view class="actions-favorites">
						<swiper :indicator-dots="false" :autoplay="true" :interval="3000" :duration="1000">
							<swiper-item v-for="(item,index) in carouselList" :key="index">
								<image :src="item.imgUrl" class="carousel-image" mode=""></image>
							</swiper-item>
							<swiper-item>
								<view class="swiper-item"></view>
							</swiper-item>
						</swiper>
					</view>
				</view>
			</view>

			<view class="menu-list">
				<view class="list-cell list-cell-arrow" @click="handleHelp">
					<view class="menu-item-box">
						<view class="iconfont icon-help menu-icon"></view>
						<view>常见问题</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="handleAbout">
					<view class="menu-item-box">
						<view class="iconfont icon-aixin menu-icon"></view>
						<view>关于我们</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="handleToSetting">
					<view class="menu-item-box">
						<view class="iconfont icon-setting menu-icon"></view>
						<view>应用设置</view>
					</view>
				</view>
			</view>
			<br /><br><br>
		</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage'

	export default {
		data() {
			return {
				name: '',
				version: getApp().globalData.config.appInfo.version,
				carouselList: [{
						imgUrl: require('@/static/images/Advertisement/Commodity1.jpg')
					},
					{
						imgUrl: require('@/static/images/Advertisement/Commodity2.jpg')
					},
				],
			}
		},
		computed: {
			avatar() {
				return this.$store.state.user.avatar
			},
			windowHeight() {
				return uni.getSystemInfoSync().windowHeight - 50
			}
		},
		created() {
			console.log(this.$store.state.user)
			this.name = this.$store.state.user.name; // 使用 created 钩子来设置 name
		},
		methods: {
			handleToInfo() {
				this.$tab.navigateTo('/pages/mine/info/index')
			},
			handleToAddress() {
				this.$tab.navigateTo('/pages/mine/info/MyAddress')
			},
			handleToEditInfo() {
				this.$tab.navigateTo('/pages/mine/info/edit')
			},
			handleToSetting() {
				this.$tab.navigateTo('/pages/mine/setting/index')
			},
			handleMyService(category) {
				console.log(category);
			      uni.navigateTo({
			        url: `/pages/mine/service/MyOrder?MyOrder=${category}`
			      });
			},
			handleMyPet(){
				uni.navigateTo({
					url: `/pages/mine/service/Mypet`
				})
			},
			handleToLogin() {
				this.$tab.reLaunch('/pages/login')
			},
			handleToAvatar() {
				this.$tab.navigateTo('/pages/mine/avatar/index')
			},
			handleLogout() {
				this.$modal.confirm('确定注销并退出系统吗？').then(() => {
					this.$store.dispatch('LogOut').then(() => {
						this.$tab.reLaunch('/pages/index')
					})
				})
			},
			handleHelp() {
				this.$tab.navigateTo('/pages/mine/help/index')
			},
			handleAbout() {
				this.$tab.navigateTo('/pages/mine/about/index')
			},
			handleJiaoLiuQun() {
				this.$modal.showToast('QQ群：①133713780、②146013835')
			},
			handleBuilding() {
				this.$modal.showToast('模块建设中~')
			},
			// getUserInfo(){
			//  this.$store.dispatch('GetInfo').then(res => {
			//    console.log(res)
			// if(res.appUser.userName){
			// 	this.name=res.appUser.userName
			// }
			//  })
			// }
		}
	}
</script>

<style lang="scss">
	page {
		background-color: rgb(241, 241, 241);
	}

	.box-bg {
		background-color: #F5F5F5;
		padding: 5px 0;
	}

	.mine-container {
		width: 100%;
		height: 100%;


		.header-section {
			padding: 15px 15px 45px 15px;
			background-color: #ffffff;
			color: black;

			.login-tip {
				font-size: 18px;
				margin-left: 10px;
			}

			.cu-avatar {
				border: 2px solid #ffffff;

				.icon {
					font-size: 40px;
				}
			}

			.user-info {
				margin-left: 15px;

				.u_title {
					font-size: 18px;
					line-height: 30px;
					color: black;
					margin-bottom: 10px;
				}
				.u_address{
					font-size: 14px;
					line-height: 24px;
					color: black;
					text-align: center;
				}
			}
		}

		.swiper-item {
			margin: 5px;

			.carousel-image {
				width: 100%;
				height: 100%;
				object-fit: contain;
			}
		}

		.content-section {
			position: relative;
			top: -50px;

			.mine-actions {
				margin: 15px 15px;
				padding: 20px 0px;
				border-radius: 8px;
				background-color: white;

				.action-item {
					.icon {
						font-size: 28px;
					}

					.text {
						display: block;
						font-size: 13px;
						margin: 8px 0px;
					}

					padding-top:3%;
					padding-bottom: 3%;
					margin:0px;
				}
			}
		}
	}
</style>